      1  /**

      2     A deposit runnable makes periodic deposits to a bank account.

      3  */

      4  public class DepositRunnable implements Runnable

      5  {

      6     private static final int DELAY = 1;

      7     private BankAccount account;

      8     private double amount;

      9     private int count;

     10

     11     /**

     12        Constructs a deposit runnable.

     13        @param anAccount the account into which to deposit money

     14        @param anAmount the amount to deposit in each repetition

     15        @param aCount the number of repetitions

     16     */

     17     public DepositRunnable(BankAccount anAccount, double anAmount,

     18           int aCount)

     19     {

     20        account = anAccount;

     21        amount = anAmount;

     22        count = aCount;

     23     }

     24

     25     public void run()

     26     {

     27        try

     28        {

     29           for (int i = 1; i <= count; i++)

     30           {

     31              account.deposit(amount);

     32              Thread.sleep(DELAY);

     33           }

     34        }

     35        catch (InterruptedException exception) {}

     36     }

     37  }